﻿--TODO: Add indexes

IF OBJECT_ID(N'[dbo].[ChannelTable]', 'U') IS NOT NULL
    DROP TABLE [dbo].[ChannelTable];
GO

CREATE TABLE ChannelTable
(
    [Key] int primary key identity(1, 1),
    DevId nvarchar(63),
    DevChn smallint,
    EquipId nvarchar(63),
    EquipPhase tinyint
)

IF OBJECT_ID(N'[dbo].[AlarmTable]', 'U') IS NOT NULL
    DROP TABLE [dbo].[AlarmTable];
GO

CREATE TABLE AlarmTable
(
    [Key] bigint primary key identity(1, 1),
    ChannelKey int not null,
    AlarmTime datetime,
    AlarmType nvarchar(63),
    AlarmLevel tinyint,
    AlarmValue real
)

IF OBJECT_ID(N'[dbo].[PDTable]', 'U') IS NOT NULL
    DROP TABLE [dbo].[PDTable];
GO

CREATE TABLE PDTable
(
    [Key] bigint primary key identity(1, 1),
    ChannelKey int not null,
    PDTime datetime,
    PDMean real,
    PDMax real,
    PDPhase real,
    PDRep real,
    PDType nvarchar(63),
    PDTypeProb nvarchar(63),
    PDLoc nvarchar(63),
    PDLevel nvarchar(63),
    PDFile nvarchar(255),
    PRPSGraph varbinary(MAX)
)

